﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - EvaluateTag" 
*/ 

component 
	displayname="public.service.db.senate.sequence.EvaluateTag" 
	output=false 
	accessors=true 
	{

	property type="string" name="EvaluateSystemID" hint="评价指标体系编号";
	property type="string" name="ParentOrder" hint="一级指标编号";
		
	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/*
	* @hint "自定义排序规则"
	*/
	public string function getTagOrder() output=false {
		
		var nextID = left( getParentOrder(), 2 ) & numberFormat(1, "0_");
		
		var sql = "SELECT tag_order FROM t_target 
					WHERE es_id = :evsId AND tag_order LIKE :condition AND tag_order > :parentOrderId 
					ORDER BY tag_order DESC ";
		
		var queryObj = new Query( datasource=application.dnsMaster, maxRows=1 );
		
		queryObj.addParam( name="evsId", value=getEvaluateSystemID(), cfsqltype="cf_sql_char" );
		queryObj.addParam( name="condition", value=left( getParentOrder(), 2 ) & "__", cfsqltype="cf_sql_char" );
		queryObj.addParam( name="parentOrderId", value=getParentOrder(), cfsqltype="cf_sql_char" );

		var rs_check = queryObj.execute( sql=sql ).getResult();
		
		if ( rs_check.recordCount ) {
			/* 创建一个追加id */
			nextID = left( getParentOrder(), 2 ) & numberFormat( ( right(rs_check.tag_order, 2) + 1 ), "0_" );
		}
		
		return nextID;
	}
	
	
	/*
	* @hint "自定义排序规则"
	*/
	public string function getLevelOrder() output=false {
		
		var nextID = numberFormat(1, "0_") & "00";
		
		var sql = "SELECT tag_order FROM t_target 
					WHERE es_id = :evsId AND tag_order LIKE '__00' 
					ORDER BY tag_order DESC ";
		
		var queryObj = new Query( datasource=application.dnsMaster, maxRows=1 );
		
		queryObj.addParam( name="evsId", value=getEvaluateSystemID(), cfsqltype="cf_sql_char" );
		
		var rs_check = queryObj.execute( sql=sql ).getResult();
		
		if ( rs_check.recordCount ) {
			/* 创建一个追加id */
			nextID = numberFormat( ( left(rs_check.tag_order, 2) + 1 ), "0_" ) & "00";
		}
		
		return nextID;
	}

	/**
	* @hint "自定义主键规则"
	*/
	public string function getID() output=false {
		
		var nextID = getEvaluateSystemID() & numberFormat(1, "0__");
		
		/* 
			主键生成规则 
			
			指标体系观察点编号5位 2位评价体系代码 + 3位流水号

			Unique: EvaluateSystemID + ___
		*/
		var sql = "SELECT tag_id FROM t_target 
					WHERE es_id = :evsId 
					ORDER BY tag_id DESC ";
		
		var queryObj = new Query( datasource=application.dnsMaster, maxRows=1 );
		
		queryObj.addParam( name="evsId", value=getEvaluateSystemID(), cfsqltype="cf_sql_char" );
		
		var rs_check = queryObj.execute( sql=sql ).getResult();
		
		if ( rs_check.recordCount ) {
			/* 创建一个追加id */
			writeLog(text=getEvaluateSystemID());
			writeLog(text=numberFormat( ( right(rs_check.tag_id, 3) + 1 ), "0__" ));
			nextID = getEvaluateSystemID() & numberFormat( ( right(rs_check.tag_id, 3) + 1 ), "0__" );
			
			writeLog(text=nextID);
		}
		
		return nextID;
	}
	
}

</cfscript>